<script language="javascript">
function validate()
{
var search_query = $('#search_query').val();
if(search_query == "") {
alert("Search Query Required");
document.getElementById('search_query').focus();
return false;
}
	
}
</script>
<?php
include("amazon_api_class.php");
if(isset($_POST['SubmitSearch']))
{
    $obj = new AmazonProductAPI();
    try
    {
        $result = $obj->searchProducts($_POST['search_query'],
                                       AmazonProductAPI::DVD,
                                       "TITLE");
    }
    catch(Exception $e)
    {
        echo $e->getMessage();
    }
}
/*if(!isset($_POST['search_query']))
{
	$obj = new AmazonProductAPI();
    try
    {
        $result = $obj->searchProducts("a",
                                       AmazonProductAPI::DVD,
                                       "TITLE");
    }
    catch(Exception $e)
    {
        echo $e->getMessage();
    }
}*/
?>
<div class="mainWarpArea">
    <div class="contentwarp">
     <div class="contentwarpMiddle">
     <div class="TechnologyTbl" style=" width:100%; background-color:#FFF;">
        <table border="0" cellspacing="2" cellpadding="2" width="100%">
          <tr>
            <td align="right" valign="middle" style="padding-right:20px;">

             <?php if($_GET['view']!='sell_books') { ?>
            <div class="search" align="center">
              <form action="" method="post" >
                <label>Title / Author / ISBN / EAN / Annotation</label>
                <input id="search_query" name="search_query" value="<?php echo $_POST['search_query']?>" class="txtborder" size="40" type="text">
                <input name="SubmitSearch" value="Search" type="submit">
            </form>
			<?php } ?>
             </div>
            </td>
          </tr>
          <tr>
            <td></td>
          </tr>
          <tr>
            <td style="padding-bottom:6;padding-left:5;" colspan="2" >
            <div style="float:left; min-height:200px;">
<style type="text/css"> 
.product { margin:10px; padding: 5px; width:600px; border: 1px solid #CCC; } 
</style> 
<?php
    if(isset($_POST['search_query']))
	{
	/* Example usage of the Amazon Product Advertising API */
    // print_r($result);
	foreach ($result->Items->Item as $item)
    {
      	?>
        <div class="product" style="width:800px; padding:5px 5px 5px 5px;">
        <table width="100%" style="width:800px; border:1px solid #E4E4E4" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="15%" align="center" valign="middle">
            <img src="<?php echo $item->SmallImage->URL;?>" border="0" />
            </td>
            <td width="74%" align="left" valign="middle" class="font12">
			<?php  
                if($item->ItemAttributes->Title!=""){echo "{$item->ItemAttributes->Title}<br>";}
                if($item->ItemAttributes->Author!=""){echo "By: {$item->ItemAttributes->Author}<br>";}
                if($item->ItemAttributes->Publisher!=""){echo "{$item->ItemAttributes->Publisher}<br>";}
				if($item->ItemAttributes->PublicationDate!=""){echo "{$item->ItemAttributes->PublicationDate}<br>";}
				?></td>
            <td width="11%" align="center" valign="middle">&nbsp;</td>
          </tr>
        </table>
        </div>
        <?php
    }}else{echo "Your List is empty ";}
?>
			  <?php if($_GET['view']==""){                      
                   /*echo '<h3>Recently Updated</h3>';
		
				  $qry="select * from books where (select max(id) from books)   
				and active_status ='1' order by id desc limit 0,5";
		
				$res = $base_obj->exec_query($qry);
				$data = $base_obj->fetch_row_all($res);	
				$count = count($data);
				for($i=0;$i<$count;$i++) 
				{
					if($data[$i]['cover_image']=="")
					{
					$source ='<img src="thumb.php?file=images/noimage.jpg" width="120px" />';	
					}
					else
					{
					$source ='<img width=120px  src="thumb.php?file=uploads/books/'.$data[$i]['cover_image'].'"/>';
					}
					 echo '<table border="0" class="viewTechnology">
					 <tr><td></td><td align="left"><b>'.$data[$i]['book_name'].'</b></td></tr>
					<tr><td width=130px valign="top">'.$source.'</td>
						<td valign="top">'.stripcslashes($data[$i]['book_desc']).'
					<br><b>Edition:'.$data[$i]['edition'].'
					<br>Author:'.$data[$i]['author'].'
					<br>Published:'.$data[$i]['publisher'].'
					<br>price $'.$data[$i]['price'].'</b></td></tr>
					</table><br>';	
				}*/
                                     
           	 }
		     if($_GET['view']=="result")
			{
			 $qry="select * from books where
				book_name 	like'%".$_POST['search_query']."%'
				OR author like '%".$_POST['search_query']."%'
				OR ISBN like '%".$_POST['search_query']."%'
				OR price like'%".$_POST['search_query']."%' OR
				annotation like'%".$_POST['search_query']."%' OR
				book_desc  like'%".$_POST['search_query']."%' and active_status ='1'";
				$res = $base_obj->exec_query($qry);
				$data = $base_obj->fetch_row_all($res);				
				$count = count($data);
				if($count>0){
				for($i=0;$i<$count;$i++) 
				{
					if($data[$i]['cover_image']=="")
					{
					$source ='<img src="thumb.php?file=images/noimage.jpg" width="120px" />';	
					}
					else
					{
					$source ='<img width=120px  src="thumb.php?file=uploads/books/'.$data[$i]['cover_image'].'"/>';
					}
					 echo '<div style="width:440px; float:left;"><table border="0" class="viewTechnology" style="width:440px;">
						 <tr><td></td><td height="25" align="left" valign="middle" ><b>'.$data[$i]['book_name'].'</b></td></tr>
					<tr><td width="170px" rowspan="5" align="center" valign="top">'.$source.'</td>
					<td align="left" valign="top">Edition : <b>'.$data[$i]['edition'].'</b></td></tr>
					<tr>
					  <td align="left" valign="top">Author : <b>'.$data[$i]['author'].'</b></td>
  					</tr>
					<tr>
					  <td align="left" valign="top">Published : <b>'.$data[$i]['publisher'].'</b></td> </tr>
					<tr>
					  <td align="left" valign="top">price <b>$'.$data[$i]['price'].'</b></td></tr>
					<tr>
					  <td align="left" valign="top">'.stripcslashes($data[$i]['book_desc']).' </td> </tr>
					</table></div><br>';	
				}}
				else
				{
					echo '<p style="text-align:center;font-weight:bold">No Books Found</p>';
					
				}
			}
			   ?></div>
            </td>
                                    
          </tr>
          <tr>
            <td background="s_images/20/mdh2.gif"><img src="s_images/spacer.gif" height="2" width="2"></td>
          </tr>
          
        </table></div>
      </div>
      <!-- End contentwarpMiddle -->
     
      <!-- End contentwarp -->
      <?php include("includes/right_content.php");?>
      <div style="clear:both;"></div>
    </div>
    <!-- End mainWarpArea -->
    <div style="clear:both;"></div>
  </div>
  <!-- End Wrapper -->
